package com.xxl.job.executor.aspect;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;

/**
 * @author dingfeng
 * @version 1.0
 * @DEC
 * @date 2022/3/7 14:45
 */
@Slf4j
@Aspect
//@Component
public class XxlJobAspect   {

    public XxlJobAspect() {
        System.out.println("===>check start");
    }

    @Pointcut("@annotation(com.xxl.job.executor.annotation.LogTime)")
    public void logTime() {
    }

    @Around("logTime()")
    public Object around(ProceedingJoinPoint proceedingJoinPoint) {
        System.out.println("------------");
        Long start = System.currentTimeMillis();
        Object proceed = null;
        try {
            proceed = proceedingJoinPoint.proceed();
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
        String name = proceedingJoinPoint.getSignature().getName();
        Long cost = System.currentTimeMillis() - start;
        log.info("方法{}耗时{}", name, cost);
        return proceed;

    }

}
